const crypto = require('crypto');
const Response = require('./Response')
const {
	getTime,
} = require('../utils/dateUtils')
const _WebDB = global._WebDB

const _TableName = 'tag'
const _Feild = [
	'tag_id',
	'tag_type',
	'tag_name',
	'tag_source',
	'song_list_num',
	'hot_num',
	'new_num',
	'create_date'
]
module.exports = {

	/**
	 * 歌单列表
	 * @param  {[type]} params [description]
	 * @return {[type]}        [description]
	 */
	list: async function(params) {
		let {
			source,
			pn = 1,
			ps = 1000,
		} = params
		let result = {}
		let where = (source && source != 'all') ? ` AND tag_source = '${source}' ` : ''
		let SQL = `SELECT count(1) AS total FROM ${_TableName} WHERE 1 = 1 ${where}`
		let {
			total
		} = await _WebDB.selectOne(SQL)
		let skip = (pn - 1) * ps
		SQL = `SELECT ${_Feild.join(',')} FROM ${_TableName} WHERE 1 = 1 ${where} LIMIT ${skip}, ${ps}`
		let docs = await _WebDB.select(SQL)
		return new Response('000', '成功', {
			total,
			docs,
		})
	},

}